package com.gexiaobao.pigeon.ui.fragment.mine.tools.line

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.gexiaobao.pigeon.app.base.BaseFragment
import com.gexiaobao.pigeon.app.ext.initClose
import com.gexiaobao.pigeon.app.model.bean.FlyWeatherInfoResponse
import com.gexiaobao.pigeon.app.util.Util
import com.gexiaobao.pigeon.databinding.FragmentMatchLineDetailBinding
import com.gexiaobao.pigeon.ui.adapter.MyPagerAdapter
import com.gexiaobao.pigeon.viewmodel.MatchLineQueryViewModel
import me.hgj.jetpackmvvm.ext.nav

/**
 * @Author      : hxw
 * @Date        : 2023/6/1 9:21
 * @Describe    : 赛线查询 详情页面
 */
class FragmentMatchLineDetail :
    BaseFragment<MatchLineQueryViewModel, FragmentMatchLineDetailBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        val flyWeatherBean = arguments?.getParcelable<FlyWeatherInfoResponse>("data")
        val distance = flyWeatherBean?.let { Util.div(it.flyDistance, 1000.00, 3) }
        val title = "赛线地图  " + distance.toString() + "KM"
        mDatabind.includeBar.toolbar.initClose(title) {
            nav().navigateUp()
        }

        val fragmentList = ArrayList<Fragment>()
        val titleList = ArrayList<String>()
        flyWeatherBean?.let { FragmentLineMatch.newInstance(it) }?.let { fragmentList.add(it) }
        flyWeatherBean?.let { FragmentWeather.newInstance(it) }?.let { fragmentList.add(it) }
        flyWeatherBean?.let { FragmentWind.newInstance(it) }?.let { fragmentList.add(it) }

        titleList.add("赛线")
        titleList.add("天气")
        titleList.add("风向")

        mDatabind.viewPager.adapter =
            context?.let { MyPagerAdapter(childFragmentManager, it, fragmentList, titleList) }
        mDatabind.viewPager.offscreenPageLimit = 3
        mDatabind.tabLayout.setupWithViewPager(mDatabind.viewPager)//此方法就是让tablayout和ViewPager联动
    }
}